import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/components/Login'
import Home from '../components/Home'
import Wellcome from '@/components/Wellcome'
import Users from '@/components/user/Users'
Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  {
    path:'/login',
    name:'login',
    component:Login
  },
  {
    path:'/home',
    component:Home,
    redirect:'/wellcome',
    children:[
      {
        path:'/wellcome',
        component:Wellcome
      },
      {
        path:'/users',
        component:Users
      }
    ]
  },
 
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path=='/login'){
    next()
  }else{
  if(window.sessionStorage.getItem('token')){
    next()
  }else{
    next('/login')
  }
  }
  })
export default router
